package com.jiuxian.scheduling.rpc.rpc;

import com.jiuxian.scheduling.rpc.RequestRpc;
import com.jiuxian.scheduling.util.SiteUtil;
import com.jiuxian.scheduling.vo.SchedingVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;

/**
 * Created by wangjingqing on 2017/12/18.
 */
public class LocalRequestRpc extends RequestRpc {

    Logger logger = LoggerFactory.getLogger(LocalRequestRpc.class);
    private Method method;

    private Object targetObj;

    /**  请求参数*/
    private SchedingVO schedingVO;

    public LocalRequestRpc(){}

    public LocalRequestRpc(Method method,Object targetObj,SchedingVO schedingVO){
        this.method = method;
        this.targetObj = targetObj;
        this.schedingVO = schedingVO;
    }
    @Override
    public Object request() throws Exception{
        Object reDate = null;
        if(method != null && targetObj != null){
            reDate = method.invoke(targetObj, SiteUtil.getMethodParameter(method.getParameterTypes(), SiteUtil.getStringForJSON(schedingVO.getParameters())));
        }
        return reDate;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public Object getTargetObj() {
        return targetObj;
    }

    public void setTargetObj(Object targetObj) {
        this.targetObj = targetObj;
    }

    public SchedingVO getSchedingVO() {
        return schedingVO;
    }

    public void setSchedingVO(SchedingVO schedingVO) {
        this.schedingVO = schedingVO;
    }
}
